package com.gcb.service.impl;


import com.gcb.common.enums.AuthStatusEnum;
import com.gcb.common.enums.ShipTypeEnum;
import com.gcb.domain.bo.DockBIBO;
import com.gcb.domain.bo.ProjectBIBO;
import com.gcb.domain.bo.ShipBIBO;
import com.gcb.domain.vo.BIMainListVO;
import com.gcb.domain.vo.BISubList;
import com.gcb.service.IBIService;
import com.gcb.service.IProjectService;
import com.gcb.service.IShipService;
import com.gcb.service.IWharfService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class BIServiceImpl implements IBIService {
    @Resource
    private IShipService shipService;

    @Resource
    private IProjectService projectService;

    @Resource
    private IWharfService wharfService;


    @Override
    public BIMainListVO mainList(String city) {
        BIMainListVO vo = new BIMainListVO();
        List<ProjectBIBO> projectBOList = projectService.biList(null , city).stream().sorted(Comparator.comparing(ProjectBIBO::getKeynoteFlag)).collect(Collectors.toList());
        List<ShipBIBO> shipBOList = shipService.biList(city);
        shipBOList.forEach(x->{
            x.setShipTypeStr(ShipTypeEnum.getInfo(x.getShipType()));
            x.setStateStr(AuthStatusEnum.getInfo(x.getState()));
        });
        List<DockBIBO> dockBOList = wharfService.biList(null , city).stream().sorted(Comparator.comparing(DockBIBO::getKeynoteFlag)).collect(Collectors.toList());
        vo.setDockList(dockBOList);
        vo.setDockCount(dockBOList.size());
        vo.setProjectList(projectBOList);
        vo.setProjectCount(projectBOList.size());
        vo.setShipList(shipBOList);
        vo.setShipCount(shipBOList.size());
        return vo;
    }

    @Override
    public BISubList subList(String city) {
        List<ProjectBIBO> projectBOList = projectService.biList(1 , city);
        List<DockBIBO> dockBOList = wharfService.biList(1 , city);
        return new BISubList(dockBOList , projectBOList);
    }
}
